<?php

namespace co2_OS;

class main

{
	protected static
		$level				=	0,
		$manifest,
		$sysvars,
		$linux_user
		;
	
	public function
	__construct
	()
	{
		self::$linux_user			=	trim(`whoami`);
	
		self::$sysvars				=	json_decode(file_get_contents(co2_OS_base.'/motor/conf/sysvar'));
		
		self::$sysvars->base	=	co2_OS_base;
		
		foreach(self::$sysvars as $k=>$v)
		if(preg_match('/%\{.+\}/',$v))
		self::$sysvars->$k	=	preg_replace('/%\{(.+)\}/Ue','print_r(self::$sysvars->{"$1"},1);',$v);

		if(is_null(self::$manifest=json_decode(file_get_contents(self::$sysvars->{"apps-manifest"}))))
		throw new \Exception('could not read apps manifest');
	}
	
	public static function
	getAppsManifest
	()
	{
		return self::$manifest;
	}
	
	public static function
	getRunLevel
	()
	{
		return self::$level;
	}
	
	public static function
	getSysVar
	(
		$k
	)
	{
		return isset(self::$sysvars->$k)?self::$sysvars->$k:$k;
	}
	
	public static function
	getLinuxUser
	()
	{
		return self::$linux_user;
	}
}
